﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using Microsoft.Reporting.WebForms;
using ProcessoSeletivo.DAO;

public partial class admin_ResponseRelatorio : System.Web.UI.Page
{
    #region " Load "

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["RelBytes"] != null && Request["Tipo"] != null)
        {
            try
            {
                string filename = DateTime.Now.ToString("yyyyMMddHHmmssfff");
                Byte[] bytes = (Byte[])Session["RelBytes"];

                if (Request["Tipo"] == "PDF")
                {
                    filename += ".pdf";
                    Response.ContentType = "application/pdf";
                }
                else
                {
                    filename += ".xls";
                    Response.ContentType = "application/vnd.ms-excel";//"application/x-msexcel";
                }
                //inline; ou attachment;
                Response.Clear();
                Response.BufferOutput = false;
                Response.AddHeader("content-disposition", "inline; filename=" + filename);
                Response.OutputStream.Write(bytes, 0, bytes.Length);
                Response.Flush();
            }
            catch (Exception ex)
            {
                ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "block", "alert('Erro na geração de relatório: " + ex.Message + "');", true);
                return;
            }
        }
    }

    #endregion
}